<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>

    <div id="root">
        <!-- 遍历数组 -->
        <h2>人员列表（遍历数组）</h2>
        <ul>
            <!-- 默认key为index，将key设置为唯一区分元素的id-->
            <li v-for="p in persons" :key="p.id">
                {{p.name}}--{{p.age}}
                <input type="text">
            </li>
        </ul>
        <button @click.once="add">点击添加老王</button>
    </div>

    <script type="text/javascript">
        Vue.config.productionTip = false;//阻止vue在启动的时候生成生产提示

        const vm = new Vue({
            el:"#root",
            data:{
                persons:[
                    {id:'001',name:'张三',age:10},
                    {id:'002',name:'李四',age:20},
                    {id:'003',name:'王五',age:30}
                ]
            },
            methods:{
                add(){
                    const w = {id:'004',name:'老王',age:40};
                    this.persons.unshift(w);//将老王插入插入开头
                }
            }
        })
   </script>
</body>
</html>